import { Button, Form, Input } from "antd";
import { DirValueType } from "@/types/typesInForm/DirValueType";
import FormProps from "@/types/typesInForm/FormProps";
import VisFragment from "@/types/VisFragment";
import { baseURL } from "config";
import { formCommit } from "utils/formCommit";

const DirectoryForm = (formProps: FormProps) => {
  const onFinish = async (values: DirValueType) => {
    const { setData, setSpinning } = formProps;
    setSpinning(true);
    const res: VisFragment | null = await formCommit(
      { ...values },
      baseURL + "/dir"
    );
    if (!!res) {
      setData({
        fragment: res,
        ifSuccessful: true,
      });
    }
    setSpinning(false);
  };
  return (
    <Form {...formProps.formLayout} onFinish={onFinish}>
      <Form.Item
        label="原始目录地址"
        name="originalDir"
        rules={[{ required: true, message: "目录地址必填！" }]}
      >
        <Input placeholder="请输入原始目录本地地址" />
      </Form.Item>

      <Form.Item
        label="变更后目录地址"
        name="modifiedDir"
        rules={[{ required: true, message: "目录地址必填！" }]}
      >
        <Input placeholder="请输入变更后目录本地地址" />
      </Form.Item>

      <Form.Item>
        <Button type="primary" htmlType="submit">
          提交
        </Button>
      </Form.Item>
    </Form>
  );
};

export default DirectoryForm;
